home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic 4 Database How-To
/
Visual Basic 4 Database - How-to (The Waite Group)(1995).iso
/
select8.fr_
/
select8.fr
Wrap
Text File
|
1995-07-04
|
4KB
|
150 lines
VERSION 4.00
Begin VB.Form Form1
BackColor = &H00C0C0C0&
Caption = "Duplicate SELECTer"
ClientHeight = 3510
ClientLeft = 2070
ClientTop = 1650
ClientWidth = 7410
BeginProperty Font
name = "MS Sans Serif"
charset = 0
weight = 700
size = 8.25
underline = 0 'False
italic = 0 'False
strikethrough = 0 'False
EndProperty
Height = 3915
Left = 2010
LinkTopic = "Form1"
ScaleHeight = 3510
ScaleWidth = 7410
Top = 1305
Width = 7530
Begin VB.CommandButton cmdClose
Caption = "Close"
Height = 615
Left = 3120
TabIndex = 0
Top = 2640
Width = 1275
End
Begin VB.Label lblCount
Alignment = 2 'Center
BorderStyle = 1 'Fixed Single
Height = 255
Left = 2040
TabIndex = 3
Top = 180
Width = 735
End
Begin VB.Label Label1
BackColor = &H00C0C0C0&
Caption = "Duplicated values:"
Height = 255
Left = 300
TabIndex = 2
Top = 180
Width = 1695
End
Begin MSGrid.Grid Grid1
Height = 1935
Left = 300
TabIndex = 1
Top = 540
Width = 6795
_Version = 65536
_ExtentX = 11986
_ExtentY = 3413
_StockProps = 77
Cols = 3
FixedCols = 0
ScrollBars = 2
End
End
Attribute VB_Name = "Form1"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit
Private Sub cmdClose_Click()
End
End Sub
Private Sub Form_Load()
Dim db As DATABASE
Dim dbName As String
Dim rs As Recordset
Dim sql As String
Dim subQuery As String
Dim ct As Integer
Dim gridRow As Integer
' Get the database name and open the database.
dbName = BiblioPath() ' BiblioPath is a function in READINI.BAS
Set db = DBEngine.Workspaces(0).OpenDatabase(dbName)
' Build the subquery, starting with its SELECT statement.
subQuery = "SELECT City FROM Publishers AS Tmp"
' Group subquery records where both the City and State fields match.
subQuery = subQuery & " GROUP BY City, State"
' Add the HAVING clause to select only those subquery records that
' occur more than once.
subQuery = subQuery & " HAVING COUNT(*) > 1 AND State = Publishers.State "
' Build the SQL statement
' Start by designating the fields to be included in the recordset
' and the WHERE IN clause
sql = "SELECT City, State, [Company Name] FROM Publishers"
' Add the WHERE clause, including the subquery
sql = sql & " WHERE City IN (" & subQuery & ")"
' Sort the output recordset in by State, then by City
sql = sql & " ORDER BY State, City"
' Run the query.
Set rs = db.OpenRecordset(sql, dbOpenSnapshot)
' Make sure the query returned at least one record
If rs.RecordCount > 0 Then
' Get a count of records in the recordset and display it on the form.
rs.MoveLast
ct = rs.RecordCount
lblCount.Caption = ct
' Initialize the grid
grid1.Rows = ct + 1
grid1.ColWidth(0) = 700
grid1.ColWidth(1) = 2000
grid1.ColWidth(2) = 4000
grid1.Row = 0
grid1.Col = 0
grid1.TEXT = "STATE"
grid1.Col = 1
grid1.TEXT = "CITY"
grid1.Col = 2
grid1.TEXT = "PUBLISHER"
rs.MoveFirst
For gridRow = 1 To ct
grid1.Row = gridRow
grid1.Col = 0
grid1.TEXT = rs![State]
grid1.Col = 1
grid1.TEXT = rs![City]
grid1.Col = 2
grid1.TEXT = rs![Company Name]
rs.MoveNext
Next gridRow
End If
End Sub